package org.windblog.core.servlet.file;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.windblog.core.FileService;
import org.windblog.core.entity.File;


@SuppressWarnings("serial")
public class SetFileServlet extends HttpServlet {

	@Override
	protected void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		String key = request.getParameter("filekey").trim();
		String title = request.getParameter("title");
		String description = request.getParameter("description");
		File file = FileService.getFile(key);
		if (file==null) {
			response.sendRedirect("/admin/mediaLibrary.jsp?message=3");
		} else {
			file.setTitle(title);
			file.setDescription(description);
			FileService.setFile(file);
			response.sendRedirect("/admin/mediaLibrary.jsp?message=4");
		}
	}

}
